<template>
    <div class="list_page_div">
        <page-list :loading="loading" :table-config="tableConfig" :data-list="dataList" :height="height" show-index
                   show-operate operate-width="120" children-name="childList">
            <template #searchArea>
                <el-input v-model="param.typeName" clearable placeholder="类型名称" style="width: 200px;"></el-input>
                <el-button type="primary" @click="searchList">查询</el-button>
                <el-button type="primary" @click="resetData">重置</el-button>
                <el-button type="primary" @click="editData()" v-if="powerList.indexOf('newsArticle:insert')>-1">新增</el-button>
                <el-button type="primary" @click="editArticle">返回</el-button>
            </template>

            <template #item_releaseFlag="scope">
                {{ $common.getDicName('yesNo', scope.row.releaseFlag) }}
            </template>

            <template #operateContent="scope">
                <el-button type="text" @click="editData(scope.row.id)" v-if="powerList.indexOf('newsArticle:update')>-1">编辑</el-button>
                <el-popconfirm title="是否确定删除当前数据？" @confirm="delData(scope.row.id)" v-if="powerList.indexOf('newsArticle:delete')>-1">
                    <el-button slot="reference" type="text">删除</el-button>
                </el-popconfirm>
            </template>
        </page-list>
        <!--编辑-->
        <news-article-type-edit :visible.sync="showEdit" :id="id" @refreshList="searchList"></news-article-type-edit>
    </div>
</template>

<script>
import PageList from "@/components/grid/pageList.vue";
import NewsArticleTypeEdit from "@/views/system/news/newsArticle/component/newsArticleTypeEdit.vue";

export default {
    name: "newsArticleTypeLis",
    components: {NewsArticleTypeEdit, PageList},
    data() {
        return {
            height: 300,
            loading: false,
            showEdit: false,

            id: '',
            tableConfig: [
                {label: "父级类型", prop: "parentsIdName", width: 260},
                {label: "类型编号", prop: "typeCode", width: 220},
                {label: "类型名称", prop: "typeName", width: 260},
                {label: "类型说明", prop: "typeExplain", minWidth: 120},
                {label: "显示顺序", prop: "orderNum", width: 120},
                {label: "是否发布", prop: "releaseFlag", width: 80, slot: true},
                {label: "创建时间", prop: "createTime", width: 200}
            ],
            dataList: [],
            total: 0,
            param: {
                typeName: '',
                field: 'create_time',
                order: 'desc',
            },

            powerList: [],
        }
    },
    mounted() {
        this.$nextTick(() => {
            this.powerList = this.$common.getPowerList("newsArticle");
            this.height = (document.body.offsetHeight - 185) + "px";
        })
        this.searchList();
    },
    methods: {
        resetData() {
            this.param.typeName = '';
            this.searchList();
        },
        searchList() {
            this.loading = true;
            this.$axios.post("/CHILD_SYSTEM/newsArticleType/getTreeList", this.param).then(res => {
                this.dataList = res.data;
            }).finally(() => {
                this.loading = false;
            })
        },
        editData(id) {
            this.id = id;
            this.showEdit = true;
        },
        delData(id) {
            this.loading = true;
            this.$axios.post("/CHILD_SYSTEM/newsArticleType/delete/" + id).then(res => {
                this.searchList();
                this.$message.success(res.message);
            }).finally(() => {
                this.loading = false;
            })
        },
        editArticle() {
            this.$router.replace('/system/news/newsArticle')
        }
    }
}
</script>

<style scoped>

</style>